<template>
    <div>
        
         <el-table  v-loading="loading" :data="routes" >
            <el-table-column label="路由名称" align="center" prop="name"></el-table-column>
            <el-table-column label="Host路由" align="center" prop="hosts"></el-table-column>
            <el-table-column label="Path路由" align="center">
                <template slot-scope="scope">
                    <span v-for="path in scope.row.paths" :key="path">
                        {{path}}  
                    </span>                    
                </template>
            </el-table-column>            
            <el-table-column label="标签信息" align="center" prop="tags"></el-table-column>
            <el-table-column label="创建时间" align="center" prop="created_at" :formatter="dateFormat"></el-table-column>
            
            <el-table-column  label="操作" align="center" class-name="small-padding fixed-width">
                <template slot-scope="scope">
                    <el-button
                        size="mini"
                        type="text"
                        icon="el-icon-delete"
                        @click="handleDelete(scope.row)"
                        v-hasPermi="['kong:routes:remove']"
                    >删除</el-button>

                </template>
            </el-table-column>

        </el-table>
    </div>
</template>
<script>
import moment from 'moment'
import {kongRouteByServiceId} from '@/api/kong/routes'
export default {
    props:{
        serviceId:{
            type:String,
            required: false
        },
        pluginId:{
            type: String,
            required: false,
        }

    },
    data () {
        return {
            routes:[],
            loading: false,
        }
    },
    created(){
        this.getRoutesByServiceId();
    },
    methods:{
        getRoutesByServiceId(){
            console.log("serviceId:"+this.serviceId)
            if(this.serviceId){
                kongRouteByServiceId(this.serviceId).then(res =>{
                    this.routes=res.data;
                    console.log("routes:"+JSON.stringify(this.routes))
                })
            }
        },
        handleDelete(){

        },
        //时间处理函数
        dateFormat(row, column){
            const _date = row[column.property]*1000; 
            if(_date ==undefined){return ''};
            return moment(_date).format("YYYY-MM-DD HH:mm:ss");
        },
    }
}
</script>
<style   scoped>

</style>